package com.share.finance.risk.rules.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.common.utils.DbUtil;
import com.share.finance.risk.rules.model.db.ExecuteResult;
import com.share.finance.risk.rules.model.db.ReasonCode;
import com.share.finance.risk.rules.model.vo.ExecuteResultPageReq;
import com.share.finance.risk.rules.model.vo.ReasonCodePageReq;
import com.share.finance.risk.rules.service.IExecuteResultService;
import com.share.finance.risk.rules.service.IReasonCodeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.Map;

/**
 * <p>
 * 变量表  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-25
 */
@RestController
public class ExecuteResultController {
    @Autowired
    private IExecuteResultService executeResultService;

    @Autowired
    private IReasonCodeService reasonCodeService;
    @Autowired
    private DataSource dataSource;

    @RequestMapping(value = "/executeResult/pageList")
    public Result pageList(ExecuteResultPageReq req) {
        Page<ExecuteResult> pageResult = executeResultService.pageList(req);
        return Result.success(pageResult);
    }


    @ApiOperation("清理删除表中的数据,保留最近的n条")
    @ResponseBody
    @RequestMapping(value = "/common/deleteLog")
    public Result deleteLog(Integer retainNum) {
        final String[] tables = {"rul_execute_result"};
        Map<String, Object> reMap = DbUtil.deleteDataById(dataSource, tables, retainNum);
        return Result.success(reMap);
    }

    @ApiOperation("查询错误码")
    @ResponseBody
    @RequestMapping(value = "/reasonCode/pageList")
    public Result reasonCodePageList(ReasonCodePageReq req) {
        Page<ReasonCode> page = reasonCodeService.pageList(req);
        return Result.success(page);
    }
}
